<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>函数式组件中使用props</title>
</head>
<body>
  <div id="app"></div>
  <script src="https://cdn.staticfile.org/react/16.4.0/umd/react.development.js"></script>
  <script src="https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js"></script>
  <!-- 生产环境中不建议使用 -->
  <script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/prop-types/15.7.2/prop-types.min.js"></script>

  <script  type="text/babel">
    function Person(props) {
      const { name, sex, age } = props
      return (
        <ul>
          <li>姓名：{name}</li>
          <li>性别：{sex}</li>
          <li>年龄：{age}</li>
        </ul>
      )
    }

    // 限制props属性
    Person.propTypes = {
      name: PropTypes.string.isrequired,
      sex: PropTypes.string,
      age: PropTypes.number
    }

    // 为props指定默认值
    Person.defaultProps = {
      sex: '男',
      age: 18
    }

    ReactDOM.render(<Person name='jsthin' />, document.getElementById('app'))
  </script>
</body>
</html>